package android.slc.module.component.attchment.utils;

import cn.hutool.core.util.StrUtil;

public class AttachmentConfig {
    private static class Holder {
        private final static AttachmentConfig INSTANCE = new AttachmentConfig();
    }

    public static AttachmentConfig getInstance() {
        return Holder.INSTANCE;
    }

    private String downloadIpPort;

    private String downloadApiPart;

    private AttachmentConfig() {
    }

    public void setDownloadIpPort(String downloadIpPort) {
        this.downloadIpPort = downloadIpPort;
    }

    public String getDownloadIpPort() {
        return downloadIpPort;
    }

    public void setDownloadApiPart(String downloadApiPart) {
        this.downloadApiPart = downloadApiPart;
    }

    public String getDownloadApiPart() {
        return downloadApiPart;
    }

    public String getDownloadRequestUrl() {
        return getDownloadIpPort() + getDownloadApiPart();
    }

    /**
     * 根据文件相对路径获取文件
     *
     * @param relativePath
     * @return
     */
    public String getDownloadPathByRelative(String relativePath) {
        return getDownloadRequestUrl()  + relativePath;
    }

    public String explicitDownloadPathAuto(String downloadPath) {
        if (StrUtil.startWithAny(downloadPath, "http", "https")) {
            return downloadPath;
        }
        return getDownloadPathByRelative(downloadPath);
    }
}
